package com.cea.papyrustest.uml.createcommand;

import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Reception;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test class for {@link Reception} creation command
 * @author Remi Schnekenburger
 */
public class ReceptionCreateCommandTest extends PapyrusCommandTest {

	protected final String NAME = "Reception_0"; 
	
	private org.eclipse.uml2.uml.Class class_;

	/**
	 * Default constructor
	 * @param name the name of the test case
	 */
	public ReceptionCreateCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		// creates a class
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Class.class,model);
		stack.execute(papyrusCommand);
		this.class_ = (org.eclipse.uml2.uml.Class)((UMLElementCreateCommand)papyrusCommand).getElement();

		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Reception.class, class_);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		// execute command
		stack.execute(papyrusCommand);
		Element clazz=class_.getOwnedReception(NAME, null, null);
		assertNotNull("the reception is created",clazz);
		assertTrue("this is not a reception",((clazz)instanceof Reception));

		// undo command
		stack.undo();
		assertNull("the reception exist!", class_.getOwnedReception(NAME, null, null));

		// redo command
		stack.redo();
		clazz=class_.getOwnedReception(NAME, null, null);
		assertNotNull("the reception is re-added to class",clazz);
		assertTrue("this is not a reception",((clazz)instanceof Reception));

	}

}
